package qc.module.platform.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qc.common.core.exception.QCPromptException;
import qc.module.platform.dto.phone.OfficialPhoneConditionDto;
import qc.module.platform.dto.phone.OfficialPhoneDto;
import qc.module.platform.dto.phone.SetCategoryIdConditionDto;
import qc.module.platform.service.OfficialPhoneService;

import java.util.List;

/**
 * @projectName: qcdp
 * @package: qc.module.platform.api.controller
 * @className: OfficialPhoneController
 * @version: 1.0
 */
@RestController
@RequestMapping("/officialphone")
public class OfficialPhoneController {

    private OfficialPhoneService service;

    @Autowired
    public void setOfficialPhoneService(OfficialPhoneService service) {
        this.service = service;
    }

    //是否为逻辑删除，为true表示逻辑删除--修改记录标记，为false表示物理删除--从数据库表中删除记录
    private static final boolean isLogicDelete = false;

    /**
     * 新增号码信息
     *
     * @param dto: 新增号码信息
     * @return String 成功返回null,失败返回错误信息
     * @author QcCheng Tech
     * @date 2023/10/7
     */
    @RequestMapping(value = "/add", method = {RequestMethod.POST})
    public String add(@RequestBody OfficialPhoneDto dto) {
        return service.add(dto);
    }


    /**
     * 修改公务号码信息
     *
     * @param dto:修改信息
     * @return String 成功返回null，失败返回错误信息
     * @author QcCheng Tech
     * @date 2023/10/7
     */
    @RequestMapping(value = "/update", method = {RequestMethod.PUT, RequestMethod.POST})
    public String update(@RequestBody OfficialPhoneDto dto) {
        return service.update(dto);
    }


    /**
     * 按id删除指定公务电话，默认物理删除
     *
     * @param id: 公务电话id
     * @return String 成功返回null，失败返回错误信息
     * @author QcCheng Tech
     * @date 2023/10/7
     */
    @RequestMapping(value = "/delete", method = {RequestMethod.DELETE})
    public String deleteByParam(@RequestParam int id) throws QCPromptException {
        return service.delete(id, isLogicDelete);
    }


    /**
     * 按id删除指定公务电话，默认物理删除
     *
     * @param id: 公务电话id
     * @return String 成功返回null，失败返回错误信息
     * @author QcCheng Tech
     * @date 2023/10/7
     */
    @RequestMapping(value = "/delete/{id}", method = {RequestMethod.DELETE})
    public String deleteByPath(@PathVariable(required = true) int id) throws QCPromptException {
        return service.delete(id, isLogicDelete);
    }


    /**
     * 按号码id查询号码信息
     *
     * @param id: 号码id
     * @return OfficialPhoneDto 查询信息
     * @author QcCheng Tech
     * @date 2023/10/7
     */
    @RequestMapping(value = "/get", method = {RequestMethod.GET})
    public OfficialPhoneDto getByParam(@RequestParam Integer id) throws QCPromptException {
        return service.get(id);
    }


    /**
     * 按号码id查询号码信息
     *
     * @param id: 号码id
     * @return OfficialPhoneDto 查询信息
     * @author QcCheng Tech
     * @date 2023/10/7
     */
    @RequestMapping(value = "/get/{id}", method = {RequestMethod.GET})
    public OfficialPhoneDto getByPath(@PathVariable Integer id) throws QCPromptException {
        return service.get(id);
    }


    /**
     * 按条件查询号码
     *
     * @param condition:查询条件 可以为名称，手机号
     * @return List<OfficialPhoneDto> 返回结果集
     * @author QcCheng Tech
     * @date 2023/10/7
     */
    @RequestMapping(value = "/query", method = {RequestMethod.POST})
    public List<OfficialPhoneDto> query(@RequestBody OfficialPhoneConditionDto condition) {
        return service.query(condition);
    }

    /**
     * 设置号码分类
     *
     * @param condition: 设置分类信息
     * @return String 成功返回null，失败返回错误信息
     * @author QcCheng Tech
     * @date 2023/10/7
     */
    @RequestMapping(value = "setCategory", method = RequestMethod.POST)
    public String setCategory(@RequestBody SetCategoryIdConditionDto condition) {
        return service.setCategory(condition);
    }
}